﻿using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ZBJF.Warranty.BLL;
using ZBJF.Warranty.BLL.SMS;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.System;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.Product;
using ZBJF.Warranty.WebProvider.Filter;

namespace ZBJF.Warranty.H5.Controllers
{
    public class CommonController : Controller
    {
        [LoginFilter(IsCheck = false)]
        public ActionResult Redirect()
        {
            return View();
        }
       
        /// <summary>
        /// 创建二维码
        /// </summary>
        /// <returns></returns>
        [LoginFilter(IsCheck = false)]
        public ActionResult CreateQRCode()
        {
            var codeParams = QRCode.Init(System.Web.HttpContext.Current.Request,Request["content"]);
            // Encode the content
            if (codeParams == null || !codeParams.TryEncode())
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return View();
            }
            // Render the QR code as an image
            using (var ms = new MemoryStream())
            {
                codeParams.Render(ms);
                Response.ContentType = codeParams.ContentType;
                Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
            }
            return View();
        }
        /// <summary>
        /// 如何查询IMEI
        /// </summary>
        /// <returns></returns>
        [LoginFilter(IsCheck = false)]
        public ActionResult SearchIMEIHelp()
        {
            return View();
        }
        [LoginFilter(IsCheck = false)]
        [HttpPost]
        public JsonResult SendVerificationCodeSMS(string userPhone, string verificationCodeTemp)
        {
            var msg = string.Empty;
            ServiceFactory.SendSmsVerificationCodeLogServiceInstance.SendSMS(userPhone, verificationCodeTemp, string.Empty,
                ref msg, 5);
            return Json(new { message = msg });
        }

    }
}